# -*- coding;utf-8 -*-
"""
File name : RemoveAllFile.PY
Program IDE : PyCharm
Create file time: 2024/9/4 10:46
File Create By Author : 朱清闯
"""
import os
import shutil


# 此函数用于删除指定目录下的所有文件及文件夹
def delete_all_file_and_folder(folder):
    try:
        # 先删除目录下的所有文件
        for file_name in os.listdir(folder):
            file_path = os.path.join(folder, file_name)
            if os.path.isfile(file_path):
                os.remove(file_path)
            elif os.path.isdir(file_path):
                shutil.rmtree(file_path)
    except Exception as e:
        print(f"删除文件时发生错误: {e}")


# 计算文件夹folder目录下的所有文件
def file_count(folder):
    count = 0
    for _, _, files in os.walk(folder):
        count += len(files)
    return count


# 只删除folder目录下的文件，不递归删除子文件夹内的文件
def remove_all_file(folder):
    for filename in os.listdir(folder):
        file_path = os.path.join(folder, filename)
        if os.path.isfile(file_path):
            os.remove(file_path)
